﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ESP.Configuration
{
    public static class ConfigurationManager
    {
        private static ESPConfigurationSection _section = null;


        static ConfigurationManager()
        {
            _section = (ESPConfigurationSection)System.Configuration.ConfigurationManager.GetSection("esp");
        }

        public static string ConnectionStringName
        {
            get
            {
                return _section == null ? null : _section.ConnectionString;
            }
        }

        public static byte[] EncryptionKey
        {
            get
            {
                return _section.Security.EncryptionKey;
            }
        }

        public static string HttpPrefix
        {
            get
            {
                return "http://" + WebSiteDomain;
            }
        }

        public static string HttpsPrefix
        {
            get
            {
                return "https://" + WebSiteDomain;
            }
        }

        //public static string HttpRoot
        //{
        //    get
        //    {
        //        string root = HttpRuntime.AppDomainAppVirtualPath;
        //        int lastIndex = root.Length - 1;
        //        if (root[lastIndex] == '/')
        //            return HttpPrefix + root.Substring(0, lastIndex);

        //        return HttpPrefix + root;
        //    }
        //}

        public static string WebSiteTitle
        {
            get
            {
                return _section.WebSite.Title;
            }
        }
        public static string WebSiteDomain
        {
            get
            {
                return _section.WebSite.Domain;
            }
        }

        public static WebSiteSettings WebSite
        {
            get
            {
                return _section.WebSite;
            }
        }



        public static ProviderSettingsCollection Providers
        {
            get
            {
                return _section.Providers;
            }
        }

        public static SecuritySettings Security
        {
            get
            {
                return _section.Security;
            }
        }
    }
}
